package com.coooliang.utils;

//import com.alibaba.fastjson2.JSON;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.coooliang.apibook.ClassResource;
import com.coooliang.apibook.MainController;
import com.coooliang.po.DocumentModel;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class RouteUtil {
    private Stage stage;

    public RouteUtil(Stage stage) {
        this.stage = stage;
    }

    public void skipToMain(File file) throws IOException, DocumentException {
        this.stage.hide();
        FXMLLoader fxmlLoader = new FXMLLoader(new ClassResource().getResource("main-view.fxml"));
        Stage mainStage = fxmlLoader.load();
        MainController mainController = fxmlLoader.getController();
        if (file != null) {
            SAXReader reader = new SAXReader();
            Document document = reader.read(file);
            DocumentModel documentModel = new DocumentModel().toModel(document);
            mainController.setDocumentModel(documentModel);
            System.out.println("json = " + JSON.toJSONString(documentModel, SerializerFeature.PrettyFormat));
        }
        mainStage.setTitle("Main");
        mainStage.initStyle(StageStyle.DECORATED);
        mainStage.show();
    }

}
